from django.db import models
# === 引入Model ===
from basicweb.models import Position, RecordStatus, Phase, PhaseContent



# 记录培训信息的表 Trainee
class Trainee(models.Model):
    """记录培训信息的表"""
    eid = models.CharField(verbose_name="员工编号", max_length=50, null=False, blank=False)
    name = models.CharField(verbose_name="员工姓名", max_length=50, null=True, blank=True, default=None)
    position = models.ForeignKey(verbose_name="职位编号", to=Position, on_delete=models.PROTECT)
    status = models.ForeignKey(verbose_name="状态", to=RecordStatus, on_delete=models.PROTECT)
    onboard = models.BooleanField(verbose_name="是否在职", null=True, blank=True, default=False)
    create_time = models.DateTimeField(verbose_name="创建时间", null=True, blank=True, default=None)

    # status 有四种：未开始，未完成， 未认证 ，已认证

    class Meta:
        managed = True
        app_label = "trainweb"
        db_table = "Train_Trainee"
        verbose_name = "Trainee"
        verbose_name_plural = "Trainee"


# 培训记录的概况 ---> 对HR录入的信息做一个基本的统计 ， 每个阶段一条记录
# 字段：id<autofield>, trainee_id<外键>, phase_id<外键>, total, completed, success, fail, total_working, total_training
class Record(models.Model):
    trainee = models.ForeignKey(verbose_name="培训信息", to=Trainee, on_delete=models.PROTECT)
    phase = models.ForeignKey(verbose_name="阶段", to=Phase, on_delete=models.PROTECT)
    total_task = models.IntegerField(verbose_name="阶段任务总数", null=True, blank=True, default=0)
    completed_task = models.IntegerField(verbose_name="完成任务数", null=True, blank=True, default=0)
    pass_task = models.IntegerField(verbose_name="通过任务数数", null=True, blank=True, default=0)
    fail_task = models.IntegerField(verbose_name="失败任务数数", null=True, blank=True, default=0)
    total_working = models.FloatField(verbose_name="当前阶段总工时",null=True, blank=True, default=0.0)
    total_training = models.FloatField(verbose_name="当前阶段总培训时长", null=True, blank=True, default=0.0)
    create_time = models.DateTimeField(verbose_name="记录时间", null=True, blank=True, default=None)

    class Meta:
        managed = True
        app_label = "trainweb"
        db_table = "Train_Record"
        verbose_name = "Record"
        verbose_name_plural = "Record"


# 培训记录的详情表 ---> HR 人员录入， 每次录入一条记录
# 字段: id<autofield>, Record_id<外键>, phashcontent_id<外键>, status , working_time,training_time, remark, record_time
class RecordDetail(models.Model):
    record = models.ForeignKey(verbose_name="记录概况", to=Record, on_delete=models.PROTECT)
    phasecontent = models.ForeignKey(verbose_name="阶段内容", to=PhaseContent, on_delete=models.PROTECT)
    status = models.ForeignKey(verbose_name="状态", to=RecordStatus, on_delete=models.PROTECT)
    working_time = models.FloatField(verbose_name="工时", null=True, blank=True, default=0.0)
    training_time = models.FloatField(verbose_name="培训时长", null=True, blank=True, default=0.0)
    remark = models.TextField(verbose_name="标注", null=True, blank=True, default=None)
    record_time= models.DateTimeField(verbose_name="记录时间", null=True, blank=True, default=None)

    class Meta:
        managed = True
        app_label = "trainweb"
        db_table = "Train_RecordDetail"
        verbose_name = "RecordDetail"
        verbose_name_plural = "RecordDetail"